package od_2025A.one;

import java.util.Scanner;

/**
 * https://hydro.ac/d/coder_gather/p/oda0002
 * 示例：
 * 输入：
 * hello123world
 * hello123abc4
 * 输出：
 * hello123
 * 动态规划解决思路：
 * 动态规划定义：dp[][]数组，d[i][j]表示公共子串的长度，初始设置 d[i][j] = 0;
 * 动态转移方程
 * 当 s1[i] == s2[j] 时 dp[i][j] = dp[i-1][j-1] + 1
 * 当 s1[i] != s2[j] 时 dp[i][j] = 0
 * TODO 注意边界条件的框定,找AI优化代码
 */
public class Test03_1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String firstStr = scanner.nextLine();
        String secondStr = scanner.nextLine();
        scanner.close();

        int n = firstStr.length();
        int m = secondStr.length();
        int[][] dp = new int[n + 1][m + 1];

        String res = "";
        int maxLength = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (firstStr.charAt(i-1) == secondStr.charAt(j-1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    if (dp[i][j] > maxLength) {
                        maxLength = dp[i][j];
                        res = firstStr.substring(i - maxLength, i);
                    }
                }
            }
        }
        System.out.println(res);
    }
}
